
package com.wyzz.hr.action;

import java.util.List;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.bo.IEmpsalarydatadefBo;
import com.wyzz.hr.pojo.Empsalarydatadef;

public class AcctItemDef extends BaseAction {

	public AcctItemDef() {
		changeIodef = "";
	}

	public String execute() throws Exception {
		IEmpsalarydatadefBo defBo = (IEmpsalarydatadefBo) getBean("empsalarydatadefBo");
		datadefList = defBo.searchAll();
		return "success";
	}

	public String deleteDef(String defId) {
		String auth = DWRUtil.checkAuth("acctItemDef", "execute");
		if ("error".equals(auth))
			return "noauth";
		IEmpsalarydatadefBo defBo = (IEmpsalarydatadefBo) getBean("empsalarydatadefBo");
		if (defBo.delete(defId))
			return "success";
		else
			return "FAIL";
	}

	public String update(Empsalarydatadef datadef) {
		String auth = DWRUtil.checkAuth("acctItemDef", "execute");
		if ("error".equals(auth))
			return "noauth";
		IEmpsalarydatadefBo defBo = (IEmpsalarydatadefBo) getBean("empsalarydatadefBo");
		datadef.setEsddSortId(defBo.searchById(datadef.getEsddId())
				.getEsddSortId());
		List list = defBo.findSameName(datadef);
		if (list.size() > 0)
			return "EXISTED";
		if (defBo.update(datadef))
			return "success";
		else
			return "FAIL";
	}

	public String insert(Empsalarydatadef datadef) {
		String auth = DWRUtil.checkAuth("acctItemDef", "execute");
		if ("error".equals(auth))
			return "noauth";
		IEmpsalarydatadefBo defBo = (IEmpsalarydatadefBo) getBean("empsalarydatadefBo");
		List list = defBo.findByName(datadef.getEsddName().trim());
		if (list.size() > 0)
			return "EXISTED";
		if (defBo.insert(datadef))
			return datadef.getEsddId();
		else
			return "FAIL";
	}

	public String saveSort(String ids[]) {
		String auth = DWRUtil.checkAuth("acctItemDef", "execute");
		if ("error".equals(auth))
			return "noauth";
		IEmpsalarydatadefBo defBo = (IEmpsalarydatadefBo) getBean("empsalarydatadefBo");
		if (defBo.saveSort(ids))
			return "success";
		else
			return "FAIL";
	}

	public String refreshOMConfig(String changeIodef) {
		if (changeIodef == null || changeIodef.length() < 1
				|| !changeIodef.equals("wyzzTagsAdmin"))
			return "noauth";
		String auth = DWRUtil.checkAuth("acctItemDef", "execute");
		if ("error".equals(auth))
			return "noauth";
		IEmpsalarydatadefBo defBo = (IEmpsalarydatadefBo) getBean("empsalarydatadefBo");
		if (defBo.batchRefreshOMConfig())
			return "success";
		else
			return "FAIL";
	}

	public List getDatadefList() {
		return datadefList;
	}

	public void setDatadefList(List datadefList) {
		this.datadefList = datadefList;
	}

	public String getChangeIodef() {
		return changeIodef;
	}

	public void setChangeIodef(String changeIodef) {
		if (changeIodef != null && changeIodef.equals("wyzzTagsAdmin"))
			this.changeIodef = changeIodef;
	}

	private static final long serialVersionUID = 1L;
	private List datadefList;
	private String changeIodef;
}
